package com.ls.utils;

import java.nio.Buffer;
import java.nio.ByteBuffer;

public class NioTest {
	public static void main(String[] args) {
		new NioTest().buffer();
	}
	
public void buffer(){
	ByteBuffer b =  ByteBuffer.allocate(15);
	print(b);
	for(int i=0;i<10;i++){
		b.put((byte) i);
	}
	print(b);
	b.flip();
	print(b);
	for(int i=0;i<3;i++){
		System.out.print(b.get());
	}
	System.out.println();
	print(b);
	
	b.flip();
	print(b);
	while(b.hasRemaining()){
		System.out.print(b.get()+" ");
	}
	System.out.println();
	print(b);
}
public void print(Buffer b){
	System.out.println(String.format("position is : %d ,limit is : %d and capacity is : %s",b.position(),b.limit(),b.capacity()));
}
}
